
export default class Man {

    x = 400
    y = 400
    xSpeed = 0
    ySpeed = 0
    sprite: Laya.Sprite = new Laya.Sprite()
    scene: Laya.Scene = null
    width = 50
    height = 50
    gravity = 0.4
    alive: boolean

    constructor(scene: Laya.Scene) {
        this.scene = scene
        scene.addChild(this.sprite)
        this.sprite.graphics.drawRect(this.x,
            this.y, this.width, this.height, "#ff0000")

        Laya.stage.on(Laya.Event.KEY_DOWN, this, this.jump)
    }
    framework() {
        this.y += this.ySpeed
        this.ySpeed += this.gravity
        if (this.y > 400) {
            this.y = 400
            this.ySpeed = 0
        }
        this.sprite.graphics.clear()
        this.sprite.graphics.drawRect(this.x,
            this.y, this.width, this.height, "#ff0000")
    }

    jump(e: Laya.Event) {
        if (e.keyCode == 32 && this.stand()) {
            this.ySpeed = -10
        }
    }
    stand() {
        return true
    }
    die() {
        this.alive = false
        alert('you die')
    }
}